package com.ssyt.yt1.day13;

import java.util.Calendar;
import java.util.Date;

import com.ssyt.yt1.common.util.Util;

/**
 * 日历操作
 * 
 * @author Administrator
 *
 */
public class CalendarDemo {

	public static void main(String[] args) {
		// 阳历（注意没有农历）
		// Calendar calendar = new GregorianCalendar();
		Calendar calendar = Calendar.getInstance();

		// 注：Calendar对象获取后默认为当前时间，如果要设置自己的时间需要调用Calendar的set方法
		calendar.set(Calendar.MONTH, 1);

		System.out.println("年：" + calendar.get(Calendar.YEAR));
		System.out.println("月：" + (calendar.get(Calendar.MONTH) + 1));
		System.out.println("日："
				+ calendar.get(/* Calendar.DATE */Calendar.DAY_OF_MONTH));
		System.out.println("时：" + calendar.get(Calendar.HOUR_OF_DAY));
		System.out.println("分：" + calendar.get(Calendar.MINUTE));
		System.out.println("秒：" + calendar.get(Calendar.SECOND));
		System.out.println("星期：" + (calendar.get(Calendar.DAY_OF_WEEK) + 1));
		// 当前月最多的天数
		System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		System.out.println(calendar.getActualMinimum(Calendar.DAY_OF_MONTH));

		// 得到一个20天后的时间
		calendar.add(Calendar.DAY_OF_MONTH, 20);

		// Calendar -> Date
		Date date = calendar.getTime();
		System.out.println(Util.format(date));
	}
}
